﻿-- =============================================
-- Author:		Jon Stocksdale
-- Create date: June 24, 2016
-- Description:	This fetches a table of ALL Reg and Super Relationships for each Relationship Name
-- =============================================
CREATE FUNCTION GetALLRegandSuperRelationshipNames
(
	
)
RETURNS 
@ReturnTable TABLE 
(
	ShortRelationshipName nvarchar(50),
	OrigRelationshipName nvarchar(50)
)
AS
BEGIN
	DECLARE @NEXTRELNAME nvarchar(50)
	DECLARE RelNameCursor CURSOR FOR
		SELECT DISTINCT ShortRelationshipName FROM DefinedEntityRelationships
	OPEN RelNameCursor
	FETCH NEXT FROM RelNameCursor INTO @NEXTRELNAME
	WHILE @@FETCH_STATUS=0 BEGIN
		INSERT INTO @ReturnTable
			SELECT * FROM GetRegularAndSuperRelationshipNames(@NEXTRELNAME)
		FETCH NEXT FROM RelNameCursor INTO @NEXTRELNAME
	END
	CLOSE RelNameCursor
	DEALLOCATE RelNameCursor
	RETURN 
END